// hyb_yl/mycenter/pages/cashing/cashing.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    cashmode: [{
        "icon": 'https://7969-yiliao-kvepb-1302281264.tcb.qcloud.la/cashm1.png?sign=87a25342b526ec683ef2cc2b369aca42&t=1597416510',
        "title": '提现至微信',
      },
      // {
      //   "icon": 'https://7969-yiliao-kvepb-1302281264.tcb.qcloud.la/cashm2.png?sign=fd04a1fd18823802736319b3f91676db&t=1597416532',
      //   "title": '提现至支付宝',
      // },
      // {
      //   "icon": 'https://7969-yiliao-kvepb-1302281264.tcb.qcloud.la/cashm3.png?sign=a667bddf209f3aa06b7b8b865695bfe3&t=1597416553',
      //   "title": '提现至银行卡',
      // },
    ],
    modeindex: 0,
    money: "",
    txprice: "0.00"
  },
  modetag: function (e) {
    // console.log(e);
    const ind = e.currentTarget.dataset.ind;
    this.setData({
      modeindex: ind
    })
  },
  formSubmit: function (e) {
    console.log(e);
    const prices = Number(this.data.money);
    var id = wx.getStorageSync('mytkid')
    var ktprice = Number(this.data.info.ktmoney.countmoney)
    console.log(prices)
    if (prices == '') {
      wx.showToast({
        title: '请输入提现金额',
        icon: 'none'
      })
      return;
    } else if (prices > ktprice) {
      wx.showToast({
        title: '提现金额不能大于可提现金额',
        icon: 'none'
      })
      return;
    }
    app.util.request({
      'url': 'entry/wxapp/tuike.tixian',
      data: {
        id: id,
        txprice: ktprice
      },
      success: function (res) {
        console.log(res)

        wx.showToast({
          title: '提现成功',
          icon: 'none',
          success: function (res) {
            setTimeout(function () {
              wx.navigateBack({
                delta: 1,
              })
            }, 1500)
          }
        })
      }
    })
  },
  moneyInput(e) {
    var money;
    if (/^(\d?)+(\.\d{0,2})?$/.test(e.detail.value)) { //正则验证，提现金额小数点后不能大于两位数字
      money = e.detail.value;
    } else {
      money = e.detail.value.substring(0, e.detail.value.length - 1);
    }
    this.setData({
      money: money,
    })
  },
  allcash: function () {
    const price = this.data.info.ktmoney.countmoney;
    this.setData({
      money: price,
    })
  },
  seecash: function () {
    wx.navigateTo({
      url: '/hyb_yl/mycenter/pages/cashRecord/cashRecord',
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = wx.getStorageSync('mytkid')
    this.setData({
      id: id
    })
    //查询我的佣金
    var that = this
    app.util.request({
      'url': 'entry/wxapp/tuike.yongjin',
      data: {
        id: id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          info: res.data
        })
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})